package com.situ.mall;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

//List
@SpringBootTest
public class RedisTestList {

    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void testSetValue() {
        redisTemplate.opsForList().rightPush("nameList", "刘备");
        redisTemplate.opsForList().rightPush("nameList", "关羽");
        redisTemplate.opsForList().rightPush("nameList", "张飞");
    }

    @Test
    public void testGetValue() {
        List list = redisTemplate.opsForList().range("nameList", 0, -1);
        System.out.println(list);
    }

    @Test
    public void testSetValue2() {
        redisTemplate.opsForList().leftPush("nameList2", "刘备");
        redisTemplate.opsForList().leftPush("nameList2", "关羽");
        redisTemplate.opsForList().leftPush("nameList2", "张飞");
        redisTemplate.opsForList().leftPush("nameList2", "关羽");
    }

    @Test
    public void testGetValue2() {
        List list = redisTemplate.opsForList().range("nameList2", 0, -1);
        System.out.println(list);
    }

    @Test
    public void testSearchByIndex() {
        String str = (String) redisTemplate.opsForList().index("nameList2", 1);
        System.out.println(str);
    }

    @Test
    public void testRemoveByIndex() {
        redisTemplate.opsForList().remove("nameList2", 2, "关羽");
    }


}
